import org.elasticsearch.action.admin.indices.create.CreateIndexResponse;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.InetSocketTransportAddress;
import org.elasticsearch.transport.client.PreBuiltTransportClient;
import org.junit.Before;
import org.junit.Test;

import java.net.InetAddress;
import java.net.UnknownHostException;

public class _单节点删除索引 {

    //定义全局变量
   private  PreBuiltTransportClient transportClient;


    /*配置初始化*/
    @Before
    public void Before() throws UnknownHostException {

        //1.创建一个settings对象,xiang相当于是一个配置信息,主要配置集群的名字
          //Settings settings= Settings.builder().put("cluster.name","cluster-es").build();
            Settings settings = Settings.EMPTY;// 这个是单节点创建,等同于上面的的代码创建
        //2.创建一个客户端对象
         transportClient = new PreBuiltTransportClient(settings);
        //3.设置集群的信息(java和es引擎端口之间的连接是9300)
         transportClient.addTransportAddresses(new InetSocketTransportAddress(InetAddress.getByName("127.0.0.1"),9300));

    }

    /*创建索引库*/
    @Test
     public void deleteIndex(){
       //根据客户端对象索引的文档id 删除库中的索引 (索引库)
       transportClient.prepareDelete("blog1","content","1").get();
       //第二种方式删除 (这种方式底层就是调用上面的方法来执行删除索引的)
        // CreateIndexResponse response1= transportClient.delete(new DeleteRequest("blog1","content","1")).get();
       //关闭资源
       transportClient.close();
    }



}



